/*
   Copyright (c) 2019 LinkedIn Corp.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

package com.linkedin.r2.util.finalizer;

import com.linkedin.r2.message.Request;
import com.linkedin.r2.message.RequestContext;
import com.linkedin.r2.message.Response;


/**
 * Interface for logic that will be executed at the end of a request when the
 * response is being sent out.
 * Used to perform actions such as capturing the final request processing latency.
 *
 * @author Chris Zhang
 */
public interface RequestFinalizer
{
  /**
   * Logic that will be executed at the end of a request.
   *
   * @param request Current request.
   * @param response Current response.
   * @param requestContext Current request context.
   * @param error Will be nonnull when the request is finalized through an error code path.
   *              For example, when an exception occurs when reading/writing to a stream.
   */
  void finalizeRequest(Request request, Response response, RequestContext requestContext, Throwable error);
}
